package com.chatgpt.platformbasedchatgpt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chatgpt.platformbasedchatgpt.dao.Question;
import com.chatgpt.platformbasedchatgpt.mapper.QuestionMapper;
import com.chatgpt.platformbasedchatgpt.service.QuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Chat
 * @since 2023-12-21
 */
@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    QuestionMapper questionMapper;
    @Override
    public Question getQuestion(int id) {
        return questionMapper.selectById(id);
    }

    @Override
    public List<Question> getQuestionList(int userId) {
        List<Question> questionList = questionMapper.selectList(new LambdaQueryWrapper<Question>()
                .eq(Question::getUserId, userId));
        return questionList;
    }

    @Override
    public int insertQuestion(Question question) {
        return questionMapper.insert(question);
    }

    @Override
    public int updateQuestion(Question question) {
        return questionMapper.updateById(question);
    }

    @Override
    public int deleteQuestion(int id) {
        return questionMapper.deleteById(id);
    }

    @Override
    public List<Question> queryQuestion(Question question) {
        return questionMapper.queryQuestion(question);
    }
}
